## static/js/main.js
function fetchAbstracts() {
  fetch('/fetch-abstracts')
    .then(response => response.json())
    .then(data => {
      const container = document.getElementById('abstracts-container');
      const errorMessageElement = document.getElementById('error-message');
      // Clear previous error messages
      errorMessageElement.style.display = 'none';
      errorMessageElement.textContent = '';

      if (data.hasOwnProperty('success') && data.success) {
        container.innerHTML = ''; // Clear existing abstracts
        if (data.hasOwnProperty('abstracts') && Array.isArray(data.abstracts)) {
          data.abstracts.forEach(abstract => {
            const paragraph = document.createElement('p');
            paragraph.textContent = abstract;
            container.appendChild(paragraph);
          });
        } else {
          console.error('Invalid format for abstracts:', data);
          errorMessageElement.textContent = 'Failed to process abstracts. Please try again later.';
          errorMessageElement.style.display = 'block';
        }
      } else {
        console.error('Failed to fetch abstracts:', data.error || 'Unknown error');
        errorMessageElement.textContent = 'Failed to fetch abstracts. Please try again later.';
        errorMessageElement.style.display = 'block';
      }
    })
    .catch(error => {
      console.error('Error fetching abstracts:', error);
      const errorMessageElement = document.getElementById('error-message');
      errorMessageElement.textContent = 'Failed to fetch abstracts. Please try again later.';
      errorMessageElement.style.display = 'block';
    });
}
